home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / gdb / solib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  38.9 KB  |  1,426 lines

  1. /* Handle SunOS and SVR4 shared libraries for GDB, the GNU Debugger.
  2.    Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
  3.    
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "defs.h"
  22.  
  23. #include <sys/types.h>
  24. #include <signal.h>
  25. #include <string.h>
  26. #include <link.h>
  27. #include <sys/param.h>
  28. #include <fcntl.h>
  29.  
  30. #ifndef SVR4_SHARED_LIBS
  31.  /* SunOS shared libs need the nlist structure.  */
  32. #include <a.out.h> 
  33. #endif
  34.  
  35. #include "symtab.h"
  36. #include "bfd.h"
  37. #include "symfile.h"
  38. #include "objfiles.h"
  39. #include "gdbcore.h"
  40. #include "command.h"
  41. #include "target.h"
  42. #include "frame.h"
  43. #include "regex.h"
  44. #include "inferior.h"
  45. #include "language.h"
  46.  
  47. #define MAX_PATH_SIZE 256        /* FIXME: Should be dynamic */
  48.  
  49. /* On SVR4 systems, for the initial implementation, use some runtime startup
  50.    symbol as the "startup mapping complete" breakpoint address.  The models
  51.    for SunOS and SVR4 dynamic linking debugger support are different in that
  52.    SunOS hits one breakpoint when all mapping is complete while using the SVR4
  53.    debugger support takes two breakpoint hits for each file mapped, and
  54.    there is no way to know when the "last" one is hit.  Both these
  55.    mechanisms should be tied to a "breakpoint service routine" that
  56.    gets automatically executed whenever one of the breakpoints indicating
  57.    a change in mapping is hit.  This is a future enhancement.  (FIXME) */
  58.  
  59. #define BKPT_AT_SYMBOL 1
  60.  
  61. #if defined (BKPT_AT_SYMBOL) && defined (SVR4_SHARED_LIBS)
  62. static char *bkpt_names[] = {
  63. #ifdef SOLIB_BKPT_NAME
  64.   SOLIB_BKPT_NAME,        /* Prefer configured name if it exists. */
  65. #endif
  66.   "_start",
  67.   "main",
  68.   NULL
  69. };
  70. #endif
  71.  
  72. /* Symbols which are used to locate the base of the link map structures. */
  73.  
  74. static char *debug_base_symbols[] = {
  75. #ifdef SVR4_SHARED_LIBS
  76.   "_r_debug",    /* Most SVR4 systems, Solaris 2.1, 2.2 */
  77.   "r_debug",    /* Solaris 2.3 */
  78. #else
  79.   "_DYNAMIC",    /* SunOS */
  80. #endif
  81.   NULL
  82. };
  83.  
  84. /* local data declarations */
  85.  
  86. #ifndef SVR4_SHARED_LIBS
  87.  
  88. #define LM_ADDR(so) ((so) -> lm.lm_addr)
  89. #define LM_NEXT(so) ((so) -> lm.lm_next)
  90. #define LM_NAME(so) ((so) -> lm.lm_name)
  91. /* Test for first link map entry; first entry is a shared library. */
  92. #define IGNORE_FIRST_LINK_MAP_ENTRY(x) (0)
  93. static struct link_dynamic dynamic_copy;
  94. static struct link_dynamic_2 ld_2_copy;
  95. static struct ld_debug debug_copy;
  96. static CORE_ADDR debug_addr;
  97. static CORE_ADDR flag_addr;
  98.  
  99. #else    /* SVR4_SHARED_LIBS */
  100.  
  101. #define LM_ADDR(so) ((so) -> lm.l_addr)
  102. #define LM_NEXT(so) ((so) -> lm.l_next)
  103. #define LM_NAME(so) ((so) -> lm.l_name)
  104. /* Test for first link map entry; first entry is the exec-file. */
  105. #define IGNORE_FIRST_LINK_MAP_ENTRY(x) ((x).l_prev == NULL)
  106. static struct r_debug debug_copy;
  107. char shadow_contents[BREAKPOINT_MAX];    /* Stash old bkpt addr contents */
  108.  
  109. #endif    /* !SVR4_SHARED_LIBS */
  110.  
  111. struct so_list {
  112.   struct so_list *next;            /* next structure in linked list */
  113.   struct link_map lm;            /* copy of link map from inferior */
  114.   struct link_map *lmaddr;        /* addr in inferior lm was read from */
  115.   CORE_ADDR lmend;            /* upper addr bound of mapped object */
  116.   char so_name[MAX_PATH_SIZE];        /* shared object lib name (FIXME) */
  117.   char symbols_loaded;            /* flag: symbols read in yet? */
  118.   char from_tty;            /* flag: print msgs? */
  119.   struct objfile *objfile;        /* objfile for loaded lib */
  120.   struct section_table *sections;
  121.   struct section_table *sections_end;
  122.   struct section_table *textsection;
  123.   bfd *abfd;
  124. };
  125.  
  126. static struct so_list *so_list_head;    /* List of known shared objects */
  127. static CORE_ADDR debug_base;        /* Base of dynamic linker structures */
  128. static CORE_ADDR breakpoint_addr;    /* Address where end bkpt is set */
  129.  
  130. extern int
  131. fdmatch PARAMS ((int, int));        /* In libiberty */
  132.  
  133. /* Local function prototypes */
  134.  
  135. static void
  136. special_symbol_handling PARAMS ((struct so_list *));
  137.  
  138. static void
  139. sharedlibrary_command PARAMS ((char *, int));
  140.  
  141. static int
  142. enable_break PARAMS ((void));
  143.  
  144. static int
  145. disable_break PARAMS ((void));
  146.  
  147. static void
  148. info_sharedlibrary_command PARAMS ((char *, int));
  149.  
  150. static int
  151. symbol_add_stub PARAMS ((char *));
  152.  
  153. static struct so_list *
  154. find_solib PARAMS ((struct so_list *));
  155.  
  156. static struct link_map *
  157. first_link_map_member PARAMS ((void));
  158.  
  159. static CORE_ADDR
  160. locate_base PARAMS ((void));
  161.  
  162. static void
  163. solib_map_sections PARAMS ((struct so_list *));
  164.  
  165. #ifdef SVR4_SHARED_LIBS
  166.  
  167. static int
  168. look_for_base PARAMS ((int, CORE_ADDR));
  169.  
  170. static CORE_ADDR
  171. bfd_lookup_symbol PARAMS ((bfd *, char *));
  172.  
  173. #else
  174.  
  175. static void
  176. solib_add_common_symbols PARAMS ((struct rtc_symb *, struct objfile *));
  177.  
  178. #endif
  179.  
  180. /*
  181.  
  182. LOCAL FUNCTION
  183.  
  184.     solib_map_sections -- open bfd and build sections for shared lib
  185.  
  186. SYNOPSIS
  187.  
  188.     static void solib_map_sections (struct so_list *so)
  189.  
  190. DESCRIPTION
  191.  
  192.     Given a pointer to one of the shared objects in our list
  193.     of mapped objects, use the recorded name to open a bfd
  194.     descriptor for the object, build a section table, and then
  195.     relocate all the section addresses by the base address at
  196.     which the shared object was mapped.
  197.  
  198. FIXMES
  199.  
  200.     In most (all?) cases the shared object file name recorded in the
  201.     dynamic linkage tables will be a fully qualified pathname.  For
  202.     cases where it isn't, do we really mimic the systems search
  203.     mechanism correctly in the below code (particularly the tilde
  204.     expansion stuff?).
  205.  */
  206.  
  207. static void
  208. solib_map_sections (so)
  209.      struct so_list *so;
  210. {
  211.   char *filename;
  212.   char *scratch_pathname;
  213.   int scratch_chan;
  214.   struct section_table *p;
  215.   struct cleanup *old_chain;
  216.   bfd *abfd;
  217.   
  218.   filename = tilde_expand (so -> so_name);
  219.   old_chain = make_cleanup (free, filename);
  220.   
  221.   scratch_chan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0,
  222.             &scratch_pathname);
  223.   if (scratch_chan < 0)
  224.     {
  225.       scratch_chan = openp (getenv ("LD_LIBRARY_PATH"), 1, filename,
  226.                 O_RDONLY, 0, &scratch_pathname);
  227.     }
  228.   if (scratch_chan < 0)
  229.     {
  230.       perror_with_name (filename);
  231.     }
  232.   /* Leave scratch_pathname allocated.  abfd->name will point to it.  */
  233.  
  234.   abfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan);
  235.   if (!abfd)
  236.     {
  237.       close (scratch_chan);
  238.       error ("Could not open `%s' as an executable file: %s",
  239.          scratch_pathname, bfd_errmsg (bfd_error));
  240.     }
  241.   /* Leave bfd open, core_xfer_memory and "info files" need it.  */
  242.   so -> abfd = abfd;
  243.   abfd -> cacheable = true;
  244.  
  245.   if (!bfd_check_format (abfd, bfd_object))
  246.     {
  247.       error ("\"%s\": not in executable format: %s.",
  248.          scratch_pathname, bfd_errmsg (bfd_error));
  249.     }
  250.   if (build_section_table (abfd, &so -> sections, &so -> sections_end))
  251.     {
  252.       error ("Can't find the file sections in `%s': %s", 
  253.          bfd_get_filename (exec_bfd), bfd_errmsg (bfd_error));
  254.     }
  255.  
  256.   for (p = so -> sections; p < so -> sections_end; p++)
  257.     {
  258.       /* Relocate the section binding addresses as recorded in the shared
  259.      object's file by the base address to which the object was actually
  260.      mapped. */
  261.       p -> addr += (CORE_ADDR) LM_ADDR (so);
  262.       p -> endaddr += (CORE_ADDR) LM_ADDR (so);
  263.       so -> lmend = (CORE_ADDR) max (p -> endaddr, so -> lmend);
  264.       if (STREQ (p -> sec_ptr -> name, ".text"))
  265.     {
  266.       so -> textsection = p;
  267.     }
  268.     }
  269.  
  270.   /* Free the file names, close the file now.  */
  271.   do_cleanups (old_chain);
  272. }
  273.  
  274. /* Read all dynamically loaded common symbol definitions from the inferior
  275.    and add them to the minimal symbol table for the shared library objfile.  */
  276.  
  277. #ifndef SVR4_SHARED_LIBS
  278.  
  279. /* In GDB 4.9 this routine was a real performance hog.  According to
  280.    some gprof data which mtranle@paris.IntelliCorp.COM (Minh Tran-Le)
  281.    sent, almost all the time spend in solib_add (up to 20 minutes with
  282.    35 shared libraries) was spent here, with 5/6 in
  283.    lookup_minimal_symbol and 1/6 in read_memory.
  284.  
  285.    To fix this, we moved the call to special_symbol_handling out of the
  286.    loop in solib_add, so this only gets called once, rather than once
  287.    for every shared library, and also removed the call to lookup_minimal_symbol
  288.    in this routine.  */
  289.  
  290. static void
  291. solib_add_common_symbols (rtc_symp, objfile)
  292.     struct rtc_symb *rtc_symp;
  293.     struct objfile *objfile;
  294. {
  295.   struct rtc_symb inferior_rtc_symb;
  296.   struct nlist inferior_rtc_nlist;
  297.   int len;
  298.   char *name;
  299.   char *origname;
  300.  
  301.   init_minimal_symbol_collection ();
  302.   make_cleanup (discard_minimal_symbols, 0);
  303.  
  304.   while (rtc_symp)
  305.     {
  306.       read_memory ((CORE_ADDR) rtc_symp,
  307.            (char *) &inferior_rtc_symb,
  308.            sizeof (inferior_rtc_symb));
  309.       read_memory ((CORE_ADDR) inferior_rtc_symb.rtc_sp,
  310.            (char *) &inferior_rtc_nlist,
  311.            sizeof(inferior_rtc_nlist));
  312.       if (inferior_rtc_nlist.n_type == N_COMM)
  313.     {
  314.       /* FIXME: The length of the symbol name is not available, but in the
  315.          current implementation the common symbol is allocated immediately
  316.          behind the name of the symbol. */
  317.       len = inferior_rtc_nlist.n_value - inferior_rtc_nlist.n_un.n_strx;
  318.  
  319.       origname = name = xmalloc (len);
  320.       read_memory ((CORE_ADDR) inferior_rtc_nlist.n_un.n_name, name, len);
  321.  
  322.       /* Don't enter the symbol twice if the target is re-run. */
  323.  
  324.       if (name[0] == bfd_get_symbol_leading_char (objfile->obfd))
  325.         {
  326.           name++;
  327.         }
  328.  
  329. #if 0
  330.       /* I think this is unnecessary, GDB can probably deal with
  331.          duplicate minimal symbols, more or less.  And the duplication
  332.          which used to happen because this was called for each shared
  333.          library is gone now that we are just called once.  */
  334.       /* FIXME:  Do we really want to exclude symbols which happen
  335.          to match symbols for other locations in the inferior's
  336.          address space, even when they are in different linkage units? */
  337.       if (lookup_minimal_symbol (name, (struct objfile *) NULL) == NULL)
  338. #endif
  339.         {
  340.           name = obsavestring (name, strlen (name),
  341.                    &objfile -> symbol_obstack);
  342.           prim_record_minimal_symbol (name, inferior_rtc_nlist.n_value,
  343.                       mst_bss, objfile);
  344.         }
  345.       free (origname);
  346.     }
  347.       rtc_symp = inferior_rtc_symb.rtc_next;
  348.     }
  349.  
  350.   /* Install any minimal symbols that have been collected as the current
  351.      minimal symbols for this objfile. */
  352.  
  353.   install_minimal_symbols (objfile);
  354. }
  355.  
  356. #endif    /* SVR4_SHARED_LIBS */
  357.  
  358. #ifdef SVR4_SHARED_LIBS
  359.  
  360. /*
  361.  
  362. LOCAL FUNCTION
  363.  
  364.     bfd_lookup_symbol -- lookup the value for a specific symbol
  365.  
  366. SYNOPSIS
  367.  
  368.     CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
  369.  
  370. DESCRIPTION
  371.  
  372.     An expensive way to lookup the value of a single symbol for
  373.     bfd's that are only temporary anyway.  This is used by the
  374.     shared library support to find the address of the debugger
  375.     interface structures in the shared library.
  376.  
  377.     Note that 0 is specifically allowed as an error return (no
  378.     such symbol).
  379.  
  380.     FIXME:  See if there is a less "expensive" way of doing this.
  381.     Also see if there is already another bfd or gdb function
  382.     that specifically does this, and if so, use it.
  383. */
  384.  
  385. static CORE_ADDR
  386. bfd_lookup_symbol (abfd, symname)
  387.      bfd *abfd;
  388.      char *symname;
  389. {
  390.   unsigned int storage_needed;
  391.   asymbol *sym;
  392.   asymbol **symbol_table;
  393.   unsigned int number_of_symbols;
  394.   unsigned int i;
  395.   struct cleanup *back_to;
  396.   CORE_ADDR symaddr = 0;
  397.   
  398.   storage_needed = get_symtab_upper_bound (abfd);
  399.  
  400.   if (storage_needed > 0)
  401.     {
  402.       symbol_table = (asymbol **) xmalloc (storage_needed);
  403.       back_to = make_cleanup (free, (PTR)symbol_table);
  404.       number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); 
  405.   
  406.       for (i = 0; i < number_of_symbols; i++)
  407.     {
  408.       sym = *symbol_table++;
  409.       if (STREQ (sym -> name, symname))
  410.         {
  411.           /* Bfd symbols are section relative. */
  412.           symaddr = sym -> value + sym -> section -> vma;
  413.           break;
  414.         }
  415.     }
  416.       do_cleanups (back_to);
  417.     }
  418.   return (symaddr);
  419. }
  420.  
  421. /*
  422.  
  423. LOCAL FUNCTION
  424.  
  425.     look_for_base -- examine file for each mapped address segment
  426.  
  427. SYNOPSYS
  428.  
  429.     static int look_for_base (int fd, CORE_ADDR baseaddr)
  430.  
  431. DESCRIPTION
  432.  
  433.     This function is passed to proc_iterate_over_mappings, which
  434.     causes it to get called once for each mapped address space, with
  435.     an open file descriptor for the file mapped to that space, and the
  436.     base address of that mapped space.
  437.  
  438.     Our job is to find the debug base symbol in the file that this
  439.     fd is open on, if it exists, and if so, initialize the dynamic
  440.     linker structure base address debug_base.
  441.  
  442.     Note that this is a computationally expensive proposition, since
  443.     we basically have to open a bfd on every call, so we specifically
  444.     avoid opening the exec file.
  445.  */
  446.  
  447. static int
  448. look_for_base (fd, baseaddr)
  449.      int fd;
  450.      CORE_ADDR baseaddr;
  451. {
  452.   bfd *interp_bfd;
  453.   CORE_ADDR address;
  454.   char **symbolp;
  455.  
  456.   /* If the fd is -1, then there is no file that corresponds to this
  457.      mapped memory segment, so skip it.  Also, if the fd corresponds
  458.      to the exec file, skip it as well. */
  459.  
  460.   if ((fd == -1) || fdmatch (fileno ((GDB_FILE *)(exec_bfd -> iostream)), fd))
  461.     {
  462.       return (0);
  463.     }
  464.  
  465.   /* Try to open whatever random file this fd corresponds to.  Note that
  466.      we have no way currently to find the filename.  Don't gripe about
  467.      any problems we might have, just fail. */
  468.  
  469.   if ((interp_bfd = bfd_fdopenr ("unnamed", gnutarget, fd)) == NULL)
  470.     {
  471.       return (0);
  472.     }
  473.   if (!bfd_check_format (interp_bfd, bfd_object))
  474.     {
  475.       bfd_close (interp_bfd);
  476.       return (0);
  477.     }
  478.  
  479.   /* Now try to find our debug base symbol in this file, which we at
  480.      least know to be a valid ELF executable or shared library. */
  481.  
  482.   for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
  483.     {
  484.       address = bfd_lookup_symbol (interp_bfd, *symbolp);
  485.       if (address != 0)
  486.     {
  487.       break;
  488.     }
  489.     }
  490.   if (address == 0)
  491.     {
  492.       bfd_close (interp_bfd);
  493.       return (0);
  494.     }
  495.  
  496.   /* Eureka!  We found the symbol.  But now we may need to relocate it
  497.      by the base address.  If the symbol's value is less than the base
  498.      address of the shared library, then it hasn't yet been relocated
  499.      by the dynamic linker, and we have to do it ourself.  FIXME: Note
  500.      that we make the assumption that the first segment that corresponds
  501.      to the shared library has the base address to which the library
  502.      was relocated. */
  503.  
  504.   if (address < baseaddr)
  505.     {
  506.       address += baseaddr;
  507.     }
  508.   debug_base = address;
  509.   bfd_close (interp_bfd);
  510.   return (1);
  511. }
  512.  
  513. #endif
  514.  
  515. /*
  516.  
  517. LOCAL FUNCTION
  518.  
  519.     locate_base -- locate the base address of dynamic linker structs
  520.  
  521. SYNOPSIS
  522.  
  523.     CORE_ADDR locate_base (void)
  524.  
  525. DESCRIPTION
  526.  
  527.     For both the SunOS and SVR4 shared library implementations, if the
  528.     inferior executable has been linked dynamically, there is a single
  529.     address somewhere in the inferior's data space which is the key to
  530.     locating all of the dynamic linker's runtime structures.  This
  531.     address is the value of the debug base symbol.  The job of this
  532.     function is to find and return that address, or to return 0 if there
  533.     is no such address (the executable is statically linked for example).
  534.  
  535.     For SunOS, the job is almost trivial, since the dynamic linker and
  536.     all of it's structures are statically linked to the executable at
  537.     link time.  Thus the symbol for the address we are looking for has
  538.     already been added to the minimal symbol table for the executable's
  539.     objfile at the time the symbol file's symbols were read, and all we
  540.     have to do is look it up there.  Note that we explicitly do NOT want
  541.     to find the copies in the shared library.
  542.  
  543.     The SVR4 version is much more complicated because the dynamic linker
  544.     and it's structures are located in the shared C library, which gets
  545.     run as the executable's "interpreter" by the kernel.  We have to go
  546.     to a lot more work to discover the address of the debug base symbol.
  547.     Because of this complexity, we cache the value we find and return that
  548.     value on subsequent invocations.  Note there is no copy in the
  549.     executable symbol tables.
  550.  
  551.     Note that we can assume nothing about the process state at the time
  552.     we need to find this address.  We may be stopped on the first instruc-
  553.     tion of the interpreter (C shared library), the first instruction of
  554.     the executable itself, or somewhere else entirely (if we attached
  555.     to the process for example).
  556.  
  557.  */
  558.  
  559. static CORE_ADDR
  560. locate_base ()
  561. {
  562.  
  563. #ifndef SVR4_SHARED_LIBS
  564.  
  565.   struct minimal_symbol *msymbol;
  566.   CORE_ADDR address = 0;
  567.   char **symbolp;
  568.  
  569.   /* For SunOS, we want to limit the search for the debug base symbol to the
  570.      executable being debugged, since there is a duplicate named symbol in the
  571.      shared library.  We don't want the shared library versions. */
  572.  
  573.   for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
  574.     {
  575.       msymbol = lookup_minimal_symbol (*symbolp, symfile_objfile);
  576.       if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
  577.     {
  578.       address = SYMBOL_VALUE_ADDRESS (msymbol);
  579.       return (address);
  580.     }
  581.     }
  582.   return (0);
  583.  
  584. #else    /* SVR4_SHARED_LIBS */
  585.  
  586.   /* Check to see if we have a currently valid address, and if so, avoid
  587.      doing all this work again and just return the cached address.  If
  588.      we have no cached address, ask the /proc support interface to iterate
  589.      over the list of mapped address segments, calling look_for_base() for
  590.      each segment.  When we are done, we will have either found the base
  591.      address or not. */
  592.  
  593.   if (debug_base == 0)
  594.     {
  595.       proc_iterate_over_mappings (look_for_base);
  596.     }
  597.   return (debug_base);
  598.  
  599. #endif    /* !SVR4_SHARED_LIBS */
  600.  
  601. }
  602.  
  603. /*
  604.  
  605. LOCAL FUNCTION
  606.  
  607.     first_link_map_member -- locate first member in dynamic linker's map
  608.  
  609. SYNOPSIS
  610.  
  611.     static struct link_map *first_link_map_member (void)
  612.  
  613. DESCRIPTION
  614.  
  615.     Read in a copy of the first member in the inferior's dynamic
  616.     link map from the inferior's dynamic linker structures, and return
  617.     a pointer to the copy in our address space.
  618. */
  619.  
  620. static struct link_map *
  621. first_link_map_member ()
  622. {
  623.   struct link_map *lm = NULL;
  624.  
  625. #ifndef SVR4_SHARED_LIBS
  626.  
  627.   read_memory (debug_base, (char *) &dynamic_copy, sizeof (dynamic_copy));
  628.   if (dynamic_copy.ld_version >= 2)
  629.     {
  630.       /* It is a version that we can deal with, so read in the secondary
  631.      structure and find the address of the link map list from it. */
  632.       read_memory ((CORE_ADDR) dynamic_copy.ld_un.ld_2, (char *) &ld_2_copy,
  633.            sizeof (struct link_dynamic_2));
  634.       lm = ld_2_copy.ld_loaded;
  635.     }
  636.  
  637. #else    /* SVR4_SHARED_LIBS */
  638.  
  639.   read_memory (debug_base, (char *) &debug_copy, sizeof (struct r_debug));
  640.   /* FIXME:  Perhaps we should validate the info somehow, perhaps by
  641.      checking r_version for a known version number, or r_state for
  642.      RT_CONSISTENT. */
  643.   lm = debug_copy.r_map;
  644.  
  645. #endif    /* !SVR4_SHARED_LIBS */
  646.  
  647.   return (lm);
  648. }
  649.  
  650. /*
  651.  
  652. LOCAL FUNCTION
  653.  
  654.     find_solib -- step through list of shared objects
  655.  
  656. SYNOPSIS
  657.  
  658.     struct so_list *find_solib (struct so_list *so_list_ptr)
  659.  
  660. DESCRIPTION
  661.  
  662.     This module contains the routine which finds the names of any
  663.     loaded "images" in the current process. The argument in must be
  664.     NULL on the first call, and then the returned value must be passed
  665.     in on subsequent calls. This provides the capability to "step" down
  666.     the list of loaded objects. On the last object, a NULL value is
  667.     returned.
  668.  
  669.     The arg and return value are "struct link_map" pointers, as defined
  670.     in <link.h>.
  671.  */
  672.  
  673. static struct so_list *
  674. find_solib (so_list_ptr)
  675.      struct so_list *so_list_ptr;    /* Last lm or NULL for first one */
  676. {
  677.   struct so_list *so_list_next = NULL;
  678.   struct link_map *lm = NULL;
  679.   struct so_list *new;
  680.   
  681.   if (so_list_ptr == NULL)
  682.     {
  683.       /* We are setting up for a new scan through the loaded images. */
  684.       if ((so_list_next = so_list_head) == NULL)
  685.     {
  686.       /* We have not already read in the dynamic linking structures
  687.          from the inferior, lookup the address of the base structure. */
  688.       debug_base = locate_base ();
  689.       if (debug_base != 0)
  690.         {
  691.           /* Read the base structure in and find the address of the first
  692.          link map list member. */
  693.           lm = first_link_map_member ();
  694.         }
  695.     }
  696.     }
  697.   else
  698.     {
  699.       /* We have been called before, and are in the process of walking
  700.      the shared library list.  Advance to the next shared object. */
  701.       if ((lm = LM_NEXT (so_list_ptr)) == NULL)
  702.     {
  703.       /* We have hit the end of the list, so check to see if any were
  704.          added, but be quiet if we can't read from the target any more. */
  705.       int status = target_read_memory ((CORE_ADDR) so_list_ptr -> lmaddr,
  706.                        (char *) &(so_list_ptr -> lm),
  707.                        sizeof (struct link_map));
  708.       if (status == 0)
  709.         {
  710.           lm = LM_NEXT (so_list_ptr);
  711.         }
  712.       else
  713.         {
  714.           lm = NULL;
  715.         }
  716.     }
  717.       so_list_next = so_list_ptr -> next;
  718.     }
  719.   if ((so_list_next == NULL) && (lm != NULL))
  720.     {
  721.       /* Get next link map structure from inferior image and build a local
  722.      abbreviated load_map structure */
  723.       new = (struct so_list *) xmalloc (sizeof (struct so_list));
  724.       memset ((char *) new, 0, sizeof (struct so_list));
  725.       new -> lmaddr = lm;
  726.       /* Add the new node as the next node in the list, or as the root
  727.      node if this is the first one. */
  728.       if (so_list_ptr != NULL)
  729.     {
  730.       so_list_ptr -> next = new;
  731.     }
  732.       else
  733.     {
  734.       so_list_head = new;
  735.     }      
  736.       so_list_next = new;
  737.       read_memory ((CORE_ADDR) lm, (char *) &(new -> lm),
  738.            sizeof (struct link_map));
  739.       /* For SVR4 versions, the first entry in the link map is for the
  740.      inferior executable, so we must ignore it.  For some versions of
  741.      SVR4, it has no name.  For others (Solaris 2.3 for example), it
  742.      does have a name, so we can no longer use a missing name to
  743.      decide when to ignore it. */
  744.       if (!IGNORE_FIRST_LINK_MAP_ENTRY (new -> lm))
  745.     {
  746.       if (!target_read_string((CORE_ADDR) LM_NAME (new), new -> so_name,
  747.               MAX_PATH_SIZE - 1))
  748.           error ("find_solib: Can't read pathname for load map\n");
  749.       new -> so_name[MAX_PATH_SIZE - 1] = 0;
  750.       solib_map_sections (new);
  751.     }      
  752.     }
  753.   return (so_list_next);
  754. }
  755.  
  756. /* A small stub to get us past the arg-passing pinhole of catch_errors.  */
  757.  
  758. static int
  759. symbol_add_stub (arg)
  760.      char *arg;
  761. {
  762.   register struct so_list *so = (struct so_list *) arg;    /* catch_errs bogon */
  763.   
  764.   so -> objfile = symbol_file_add (so -> so_name, so -> from_tty,
  765.                    (unsigned int) so -> textsection -> addr,
  766.                    0, 0, 0);
  767.   return (1);
  768. }
  769.  
  770. /*
  771.  
  772. GLOBAL FUNCTION
  773.  
  774.     solib_add -- add a shared library file to the symtab and section list
  775.  
  776. SYNOPSIS
  777.  
  778.     void solib_add (char *arg_string, int from_tty,
  779.             struct target_ops *target)
  780.  
  781. DESCRIPTION
  782.  
  783. */
  784.  
  785. void
  786. solib_add (arg_string, from_tty, target)
  787.      char *arg_string;
  788.      int from_tty;
  789.      struct target_ops *target;
  790. {    
  791.   register struct so_list *so = NULL;       /* link map state variable */
  792.  
  793.   /* Last shared library that we read.  */
  794.   struct so_list *so_last = NULL;
  795.  
  796.   char *re_err;
  797.   int count;
  798.   int old;
  799.   
  800.   if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL)
  801.     {
  802.       error ("Invalid regexp: %s", re_err);
  803.     }
  804.   
  805.   /* Getting new symbols may change our opinion about what is
  806.      frameless.  */
  807.   reinit_frame_cache ();
  808.   
  809.   while ((so = find_solib (so)) != NULL)
  810.     {
  811.       if (so -> so_name[0] && re_exec (so -> so_name))
  812.     {
  813.       so -> from_tty = from_tty;
  814.       if (so -> symbols_loaded)
  815.         {
  816.           if (from_tty)
  817.         {
  818.           printf_unfiltered ("Symbols already loaded for %s\n", so -> so_name);
  819.         }
  820.         }
  821.       else if (catch_errors
  822.            (symbol_add_stub, (char *) so,
  823.             "Error while reading shared library symbols:\n",
  824.             RETURN_MASK_ALL))
  825.         {
  826.           so_last = so;
  827.           so -> symbols_loaded = 1;
  828.         }
  829.     }
  830.     }
  831.   
  832.   /* Now add the shared library sections to the section table of the
  833.      specified target, if any.  */
  834.   if (target)
  835.     {
  836.       /* Count how many new section_table entries there are.  */
  837.       so = NULL;
  838.       count = 0;
  839.       while ((so = find_solib (so)) != NULL)
  840.     {
  841.       if (so -> so_name[0])
  842.         {
  843.           count += so -> sections_end - so -> sections;
  844.         }
  845.     }
  846.       
  847.       if (count)
  848.     {
  849.       /* Reallocate the target's section table including the new size.  */
  850.       if (target -> to_sections)
  851.         {
  852.           old = target -> to_sections_end - target -> to_sections;
  853.           target -> to_sections = (struct section_table *)
  854.         xrealloc ((char *)target -> to_sections,
  855.              (sizeof (struct section_table)) * (count + old));
  856.         }
  857.       else
  858.         {
  859.           old = 0;
  860.           target -> to_sections = (struct section_table *)
  861.         xmalloc ((sizeof (struct section_table)) * count);
  862.         }
  863.       target -> to_sections_end = target -> to_sections + (count + old);
  864.       
  865.       /* Add these section table entries to the target's table.  */
  866.       while ((so = find_solib (so)) != NULL)
  867.         {
  868.           if (so -> so_name[0])
  869.         {
  870.           count = so -> sections_end - so -> sections;
  871.           memcpy ((char *) (target -> to_sections + old),
  872.               so -> sections, 
  873.               (sizeof (struct section_table)) * count);
  874.           old += count;
  875.         }
  876.         }
  877.     }
  878.     }
  879.  
  880.   /* Calling this once at the end means that we put all the minimal
  881.      symbols for commons into the objfile for the last shared library.
  882.      Since they are in common, this should not be a problem.  If we
  883.      delete the objfile with the minimal symbols, we can put all the
  884.      symbols into a new objfile (and will on the next call to solib_add).
  885.  
  886.      An alternate approach would be to create an objfile just for
  887.      common minsyms, thus not needing any objfile argument to
  888.      solib_add_common_symbols.  */
  889.  
  890.   if (so_last)
  891.     special_symbol_handling (so_last);
  892. }
  893.  
  894. /*
  895.  
  896. LOCAL FUNCTION
  897.  
  898.     info_sharedlibrary_command -- code for "info sharedlibrary"
  899.  
  900. SYNOPSIS
  901.  
  902.     static void info_sharedlibrary_command ()
  903.  
  904. DESCRIPTION
  905.  
  906.     Walk through the shared library list and print information
  907.     about each attached library.
  908. */
  909.  
  910. static void
  911. info_sharedlibrary_command (ignore, from_tty)
  912.      char *ignore;
  913.      int from_tty;
  914. {
  915.   register struct so_list *so = NULL;      /* link map state variable */
  916.   int header_done = 0;
  917.   
  918.   if (exec_bfd == NULL)
  919.     {
  920.       printf_unfiltered ("No exec file.\n");
  921.       return;
  922.     }
  923.   while ((so = find_solib (so)) != NULL)
  924.     {
  925.       if (so -> so_name[0])
  926.     {
  927.       if (!header_done)
  928.         {
  929.           printf_unfiltered("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read",
  930.              "Shared Object Library");
  931.           header_done++;
  932.         }
  933.       printf_unfiltered ("%-12s",
  934.           local_hex_string_custom ((unsigned long) LM_ADDR (so),
  935.                        "08l"));
  936.       printf_unfiltered ("%-12s",
  937.           local_hex_string_custom ((unsigned long) so -> lmend,
  938.                        "08l"));
  939.       printf_unfiltered ("%-12s", so -> symbols_loaded ? "Yes" : "No");
  940.       printf_unfiltered ("%s\n",  so -> so_name);
  941.     }
  942.     }
  943.   if (so_list_head == NULL)
  944.     {
  945.       printf_unfiltered ("No shared libraries loaded at this time.\n");    
  946.     }
  947. }
  948.  
  949. /*
  950.  
  951. GLOBAL FUNCTION
  952.  
  953.     solib_address -- check to see if an address is in a shared lib
  954.  
  955. SYNOPSIS
  956.  
  957.     int solib_address (CORE_ADDR address)
  958.  
  959. DESCRIPTION
  960.  
  961.     Provides a hook for other gdb routines to discover whether or
  962.     not a particular address is within the mapped address space of
  963.     a shared library.  Any address between the base mapping address
  964.     and the first address beyond the end of the last mapping, is
  965.     considered to be within the shared library address space, for
  966.     our purposes.
  967.  
  968.     For example, this routine is called at one point to disable
  969.     breakpoints which are in shared libraries that are not currently
  970.     mapped in.
  971.  */
  972.  
  973. int
  974. solib_address (address)
  975.      CORE_ADDR address;
  976. {
  977.   register struct so_list *so = 0;       /* link map state variable */
  978.   
  979.   while ((so = find_solib (so)) != NULL)
  980.     {
  981.       if (so -> so_name[0])
  982.     {
  983.       if ((address >= (CORE_ADDR) LM_ADDR (so)) &&
  984.           (address < (CORE_ADDR) so -> lmend))
  985.         {
  986.           return (1);
  987.         }
  988.     }
  989.     }
  990.   return (0);
  991. }
  992.  
  993. /* Called by free_all_symtabs */
  994.  
  995. void 
  996. clear_solib()
  997. {
  998.   struct so_list *next;
  999.   char *bfd_filename;
  1000.   
  1001.   while (so_list_head)
  1002.     {
  1003.       if (so_list_head -> sections)
  1004.     {
  1005.       free ((PTR)so_list_head -> sections);
  1006.     }
  1007.       if (so_list_head -> abfd)
  1008.     {
  1009.       bfd_filename = bfd_get_filename (so_list_head -> abfd);
  1010.       bfd_close (so_list_head -> abfd);
  1011.     }
  1012.       else
  1013.     /* This happens for the executable on SVR4.  */
  1014.     bfd_filename = NULL;
  1015.       
  1016.       next = so_list_head -> next;
  1017.       if (bfd_filename)
  1018.     free ((PTR)bfd_filename);
  1019.       free ((PTR)so_list_head);
  1020.       so_list_head = next;
  1021.     }
  1022.   debug_base = 0;
  1023. }
  1024.  
  1025. /*
  1026.  
  1027. LOCAL FUNCTION
  1028.  
  1029.     disable_break -- remove the "mapping changed" breakpoint
  1030.  
  1031. SYNOPSIS
  1032.  
  1033.     static int disable_break ()
  1034.  
  1035. DESCRIPTION
  1036.  
  1037.     Removes the breakpoint that gets hit when the dynamic linker
  1038.     completes a mapping change.
  1039.  
  1040. */
  1041.  
  1042. static int
  1043. disable_break ()
  1044. {
  1045.   int status = 1;
  1046.  
  1047. #ifndef SVR4_SHARED_LIBS
  1048.  
  1049.   int in_debugger = 0;
  1050.   
  1051.   /* Read the debugger structure from the inferior to retrieve the
  1052.      address of the breakpoint and the original contents of the
  1053.      breakpoint address.  Remove the breakpoint by writing the original
  1054.      contents back. */
  1055.  
  1056.   read_memory (debug_addr, (char *) &debug_copy, sizeof (debug_copy));
  1057.  
  1058.   /* Set `in_debugger' to zero now. */
  1059.  
  1060.   write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
  1061.  
  1062.   breakpoint_addr = (CORE_ADDR) debug_copy.ldd_bp_addr;
  1063.   write_memory (breakpoint_addr, (char *) &debug_copy.ldd_bp_inst,
  1064.         sizeof (debug_copy.ldd_bp_inst));
  1065.  
  1066. #else    /* SVR4_SHARED_LIBS */
  1067.  
  1068.   /* Note that breakpoint address and original contents are in our address
  1069.      space, so we just need to write the original contents back. */
  1070.  
  1071.   if (memory_remove_breakpoint (breakpoint_addr, shadow_contents) != 0)
  1072.     {
  1073.       status = 0;
  1074.     }
  1075.  
  1076. #endif    /* !SVR4_SHARED_LIBS */
  1077.  
  1078.   /* For the SVR4 version, we always know the breakpoint address.  For the
  1079.      SunOS version we don't know it until the above code is executed.
  1080.      Grumble if we are stopped anywhere besides the breakpoint address. */
  1081.  
  1082.   if (stop_pc != breakpoint_addr)
  1083.     {
  1084.       warning ("stopped at unknown breakpoint while handling shared libraries");
  1085.     }
  1086.  
  1087.   return (status);
  1088. }
  1089.  
  1090. /*
  1091.  
  1092. LOCAL FUNCTION
  1093.  
  1094.     enable_break -- arrange for dynamic linker to hit breakpoint
  1095.  
  1096. SYNOPSIS
  1097.  
  1098.     int enable_break (void)
  1099.  
  1100. DESCRIPTION
  1101.  
  1102.     Both the SunOS and the SVR4 dynamic linkers have, as part of their
  1103.     debugger interface, support for arranging for the inferior to hit
  1104.     a breakpoint after mapping in the shared libraries.  This function
  1105.     enables that breakpoint.
  1106.  
  1107.     For SunOS, there is a special flag location (in_debugger) which we
  1108.     set to 1.  When the dynamic linker sees this flag set, it will set
  1109.     a breakpoint at a location known only to itself, after saving the
  1110.     original contents of that place and the breakpoint address itself,
  1111.     in it's own internal structures.  When we resume the inferior, it
  1112.     will eventually take a SIGTRAP when it runs into the breakpoint.
  1113.     We handle this (in a different place) by restoring the contents of
  1114.     the breakpointed location (which is only known after it stops),
  1115.     chasing around to locate the shared libraries that have been
  1116.     loaded, then resuming.
  1117.  
  1118.     For SVR4, the debugger interface structure contains a member (r_brk)
  1119.     which is statically initialized at the time the shared library is
  1120.     built, to the offset of a function (_r_debug_state) which is guaran-
  1121.     teed to be called once before mapping in a library, and again when
  1122.     the mapping is complete.  At the time we are examining this member,
  1123.     it contains only the unrelocated offset of the function, so we have
  1124.     to do our own relocation.  Later, when the dynamic linker actually
  1125.     runs, it relocates r_brk to be the actual address of _r_debug_state().
  1126.  
  1127.     The debugger interface structure also contains an enumeration which
  1128.     is set to either RT_ADD or RT_DELETE prior to changing the mapping,
  1129.     depending upon whether or not the library is being mapped or unmapped,
  1130.     and then set to RT_CONSISTENT after the library is mapped/unmapped.
  1131. */
  1132.  
  1133. static int
  1134. enable_break ()
  1135. {
  1136.   int success = 0;
  1137.  
  1138. #ifndef SVR4_SHARED_LIBS
  1139.  
  1140.   int j;
  1141.   int in_debugger;
  1142.  
  1143.   /* Get link_dynamic structure */
  1144.  
  1145.   j = target_read_memory (debug_base, (char *) &dynamic_copy,
  1146.               sizeof (dynamic_copy));
  1147.   if (j)
  1148.     {
  1149.       /* unreadable */
  1150.       return (0);
  1151.     }
  1152.  
  1153.   /* Calc address of debugger interface structure */
  1154.  
  1155.   debug_addr = (CORE_ADDR) dynamic_copy.ldd;
  1156.  
  1157.   /* Calc address of `in_debugger' member of debugger interface structure */
  1158.  
  1159.   flag_addr = debug_addr + (CORE_ADDR) ((char *) &debug_copy.ldd_in_debugger -
  1160.                     (char *) &debug_copy);
  1161.  
  1162.   /* Write a value of 1 to this member.  */
  1163.  
  1164.   in_debugger = 1;
  1165.   write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
  1166.   success = 1;
  1167.  
  1168. #else    /* SVR4_SHARED_LIBS */
  1169.  
  1170. #ifdef BKPT_AT_SYMBOL
  1171.  
  1172.   struct minimal_symbol *msymbol;
  1173.   char **bkpt_namep;
  1174.   CORE_ADDR bkpt_addr;
  1175.  
  1176.   /* Scan through the list of symbols, trying to look up the symbol and
  1177.      set a breakpoint there.  Terminate loop when we/if we succeed. */
  1178.  
  1179.   breakpoint_addr = 0;
  1180.   for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++)
  1181.     {
  1182.       msymbol = lookup_minimal_symbol (*bkpt_namep, symfile_objfile);
  1183.       if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
  1184.     {
  1185.       bkpt_addr = SYMBOL_VALUE_ADDRESS (msymbol);
  1186.       if (target_insert_breakpoint (bkpt_addr, shadow_contents) == 0)
  1187.         {
  1188.           breakpoint_addr = bkpt_addr;
  1189.           success = 1;
  1190.           break;
  1191.         }
  1192.     }
  1193.     }
  1194.  
  1195. #else    /* !BKPT_AT_SYMBOL */
  1196.  
  1197.   struct symtab_and_line sal;
  1198.  
  1199.   /* Read the debugger interface structure directly. */
  1200.  
  1201.   read_memory (debug_base, (char *) &debug_copy, sizeof (debug_copy));
  1202.  
  1203.   /* Set breakpoint at the debugger interface stub routine that will
  1204.      be called just prior to each mapping change and again after the
  1205.      mapping change is complete.  Set up the (nonexistent) handler to
  1206.      deal with hitting these breakpoints.  (FIXME). */
  1207.  
  1208.   warning ("'%s': line %d: missing SVR4 support code", __FILE__, __LINE__);
  1209.   success = 1;
  1210.  
  1211. #endif    /* BKPT_AT_SYMBOL */
  1212.  
  1213. #endif    /* !SVR4_SHARED_LIBS */
  1214.  
  1215.   return (success);
  1216. }
  1217.   
  1218. /*
  1219.   
  1220. GLOBAL FUNCTION
  1221.   
  1222.     solib_create_inferior_hook -- shared library startup support
  1223.   
  1224. SYNOPSIS
  1225.   
  1226.     void solib_create_inferior_hook()
  1227.   
  1228. DESCRIPTION
  1229.   
  1230.     When gdb starts up the inferior, it nurses it along (through the
  1231.     shell) until it is ready to execute it's first instruction.  At this
  1232.     point, this function gets called via expansion of the macro
  1233.     SOLIB_CREATE_INFERIOR_HOOK.
  1234.  
  1235.     For SunOS executables, this first instruction is typically the
  1236.     one at "_start", or a similar text label, regardless of whether
  1237.     the executable is statically or dynamically linked.  The runtime
  1238.     startup code takes care of dynamically linking in any shared
  1239.     libraries, once gdb allows the inferior to continue.
  1240.  
  1241.     For SVR4 executables, this first instruction is either the first
  1242.     instruction in the dynamic linker (for dynamically linked
  1243.     executables) or the instruction at "start" for statically linked
  1244.     executables.  For dynamically linked executables, the system
  1245.     first exec's /lib/libc.so.N, which contains the dynamic linker,
  1246.     and starts it running.  The dynamic linker maps in any needed
  1247.     shared libraries, maps in the actual user executable, and then
  1248.     jumps to "start" in the user executable.
  1249.  
  1250.     For both SunOS shared libraries, and SVR4 shared libraries, we
  1251.     can arrange to cooperate with the dynamic linker to discover the
  1252.     names of shared libraries that are dynamically linked, and the
  1253.     base addresses to which they are linked.
  1254.  
  1255.     This function is responsible for discovering those names and
  1256.     addresses, and saving sufficient information about them to allow
  1257.     their symbols to be read at a later time.
  1258.  
  1259. FIXME
  1260.  
  1261.     Between enable_break() and disable_break(), this code does not
  1262.     properly handle hitting breakpoints which the user might have
  1263.     set in the startup code or in the dynamic linker itself.  Proper
  1264.     handling will probably have to wait until the implementation is
  1265.     changed to use the "breakpoint handler function" method.
  1266.  
  1267.     Also, what if child has exit()ed?  Must exit loop somehow.
  1268.   */
  1269.  
  1270. void 
  1271. solib_create_inferior_hook()
  1272. {
  1273.   /* If we are using the BKPT_AT_SYMBOL code, then we don't need the base
  1274.      yet.  In fact, in the case of a SunOS4 executable being run on
  1275.      Solaris, we can't get it yet.  find_solib will get it when it needs
  1276.      it.  */
  1277. #if !(defined (SVR4_SHARED_LIBS) && defined (BKPT_AT_SYMBOL))
  1278.   if ((debug_base = locate_base ()) == 0)
  1279.     {
  1280.       /* Can't find the symbol or the executable is statically linked. */
  1281.       return;
  1282.     }
  1283. #endif
  1284.  
  1285.   if (!enable_break ())
  1286.     {
  1287.       warning ("shared library handler failed to enable breakpoint");
  1288.       return;
  1289.     }
  1290.  
  1291.   /* Now run the target.  It will eventually hit the breakpoint, at
  1292.      which point all of the libraries will have been mapped in and we
  1293.      can go groveling around in the dynamic linker structures to find
  1294.      out what we need to know about them. */
  1295.  
  1296.   clear_proceed_status ();
  1297.   stop_soon_quietly = 1;
  1298.   stop_signal = TARGET_SIGNAL_0;
  1299.   do
  1300.     {
  1301.       target_resume (-1, 0, stop_signal);
  1302.       wait_for_inferior ();
  1303.     }
  1304.   while (stop_signal != TARGET_SIGNAL_TRAP);
  1305.   stop_soon_quietly = 0;
  1306.   
  1307.   /* We are now either at the "mapping complete" breakpoint (or somewhere
  1308.      else, a condition we aren't prepared to deal with anyway), so adjust
  1309.      the PC as necessary after a breakpoint, disable the breakpoint, and
  1310.      add any shared libraries that were mapped in. */
  1311.  
  1312.   if (DECR_PC_AFTER_BREAK)
  1313.     {
  1314.       stop_pc -= DECR_PC_AFTER_BREAK;
  1315.       write_register (PC_REGNUM, stop_pc);
  1316.     }
  1317.  
  1318.   if (!disable_break ())
  1319.     {
  1320.       warning ("shared library handler failed to disable breakpoint");
  1321.     }
  1322.  
  1323.   solib_add ((char *) 0, 0, (struct target_ops *) 0);
  1324. }
  1325.  
  1326. /*
  1327.  
  1328. LOCAL FUNCTION
  1329.  
  1330.     special_symbol_handling -- additional shared library symbol handling
  1331.  
  1332. SYNOPSIS
  1333.  
  1334.     void special_symbol_handling (struct so_list *so)
  1335.  
  1336. DESCRIPTION
  1337.  
  1338.     Once the symbols from a shared object have been loaded in the usual
  1339.     way, we are called to do any system specific symbol handling that 
  1340.     is needed.
  1341.  
  1342.     For Suns, this consists of grunging around in the dynamic linkers
  1343.     structures to find symbol definitions for "common" symbols and 
  1344.     adding them to the minimal symbol table for the corresponding
  1345.     objfile.
  1346.  
  1347. */
  1348.  
  1349. static void
  1350. special_symbol_handling (so)
  1351. struct so_list *so;
  1352. {
  1353. #ifndef SVR4_SHARED_LIBS
  1354.   int j;
  1355.  
  1356.   if (debug_addr == 0)
  1357.     {
  1358.       /* Get link_dynamic structure */
  1359.  
  1360.       j = target_read_memory (debug_base, (char *) &dynamic_copy,
  1361.                   sizeof (dynamic_copy));
  1362.       if (j)
  1363.     {
  1364.       /* unreadable */
  1365.       return;
  1366.     }
  1367.  
  1368.       /* Calc address of debugger interface structure */
  1369.       /* FIXME, this needs work for cross-debugging of core files
  1370.      (byteorder, size, alignment, etc).  */
  1371.  
  1372.       debug_addr = (CORE_ADDR) dynamic_copy.ldd;
  1373.     }
  1374.  
  1375.   /* Read the debugger structure from the inferior, just to make sure
  1376.      we have a current copy. */
  1377.  
  1378.   j = target_read_memory (debug_addr, (char *) &debug_copy,
  1379.               sizeof (debug_copy));
  1380.   if (j)
  1381.     return;        /* unreadable */
  1382.  
  1383.   /* Get common symbol definitions for the loaded object. */
  1384.  
  1385.   if (debug_copy.ldd_cp)
  1386.     {
  1387.       solib_add_common_symbols (debug_copy.ldd_cp, so -> objfile);
  1388.     }
  1389.  
  1390. #endif    /* !SVR4_SHARED_LIBS */
  1391. }
  1392.  
  1393.  
  1394. /*
  1395.  
  1396. LOCAL FUNCTION
  1397.  
  1398.     sharedlibrary_command -- handle command to explicitly add library
  1399.  
  1400. SYNOPSIS
  1401.  
  1402.     static void sharedlibrary_command (char *args, int from_tty)
  1403.  
  1404. DESCRIPTION
  1405.  
  1406. */
  1407.  
  1408. static void
  1409. sharedlibrary_command (args, from_tty)
  1410. char *args;
  1411. int from_tty;
  1412. {
  1413.   dont_repeat ();
  1414.   solib_add (args, from_tty, (struct target_ops *) 0);
  1415. }
  1416.  
  1417. void
  1418. _initialize_solib()
  1419. {
  1420.   
  1421.   add_com ("sharedlibrary", class_files, sharedlibrary_command,
  1422.        "Load shared object library symbols for files matching REGEXP.");
  1423.   add_info ("sharedlibrary", info_sharedlibrary_command, 
  1424.         "Status of loaded shared object libraries.");
  1425. }
  1426.